package com.yan.iterator;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author taoge
 * @Date 2024/8/1 11:01
 * @Description
 */
public class IteratorDemo2 {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();
        map.put("1" , "2");
        map.put("3" , "4");
        map.put("5" , "6");
        map.put("7" , "8");
        System.out.println("map = " + map);
        System.out.println(map.get("1"));
        Set<String> keys = map.keySet();
        keys.forEach(item-> System.out.print(item + " "));
        System.out.println(map.containsKey("1"));
        System.out.println(map.containsValue("3"));
        System.out.println(map.remove("1", "2"));
        System.out.println(map);
        System.out.println(map.remove("3"));
        System.out.println(map);
        System.out.println(map.put("5", "9"));
        System.out.println(map);

        Set<String> keys1 = map.keySet();
        for (String s : keys1) {
            System.out.println(s+ "----" + map.get(s));
        }
        System.out.println("---------------------");
        Set<Map.Entry<String, String>> entries = map.entrySet();
        Iterator<Map.Entry<String, String>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> entry = iterator.next();
            System.out.println(entry.getKey() + "----" + entry.getValue());
        }
        System.out.println("------------------------------------------------------");
        entries.forEach(item-> System.out.println(item.getKey() +"---" + item.getValue()));
        System.out.println("---------------------------------------");
        for (Map.Entry<String, String> entry : entries) {
            System.out.println(entry.getKey() + " ------" + entry.getValue());
        }
        System.out.println("---------------------------------------");
        Iterator<Map.Entry<String, String>> iterator1 = entries.iterator();
        while (iterator1.hasNext()) {
            Map.Entry<String, String> next = iterator1.next();
            System.out.println(next.getKey() + "----" + next.getValue());

        }


    }
}
